package com.minicode.google;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import android.content.Context;

import com.minicode.twitter.TwitterError;

public class AsyncGoogleRunner {

	private Google google;

	public AsyncGoogleRunner(Google google) {
		this.google = google;
	}

	public void logout(final Context context, final RequestListener listener) {
		new Thread() {
			@Override
			public void run() {
				try {
					String response = google.logout(context);
					if (response.length() == 0 || response.equals("false")) {
						listener.onTwitterError(new TwitterError(
								"auth.expireSession failed"));
						return;
					}
					listener.onComplete(response);
				} catch (FileNotFoundException e) {
					listener.onFileNotFoundException(e);
				} catch (MalformedURLException e) {
					listener.onMalformedURLException(e);
				} catch (IOException e) {
					listener.onIOException(e);
				}
			}
		}.start();
	}

	public static interface RequestListener {
		public void onComplete(String response);

		public void onIOException(IOException e);

		public void onFileNotFoundException(FileNotFoundException e);

		public void onMalformedURLException(MalformedURLException e);

		public void onTwitterError(TwitterError e);

	}
}
